﻿using DFGK_WMS.IRepository;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Newtonsoft.Json;

namespace DFGJ.WMS_PDA.WebAPI.CfgFile
{
    public class LogActionFilter : ActionFilterAttribute
    {
        private readonly ILogger<LogActionFilter> logger;
        public LogActionFilter(ILogger<LogActionFilter> logger)
        {
            this.logger = logger;
        }

        public override void OnActionExecuting(ActionExecutingContext context)
        {
            base.OnActionExecuting(context);
            Console.WriteLine("请求前：" + JsonConvert.SerializeObject(context.ActionArguments.Values));
            logger.LogInformation(JsonConvert.SerializeObject(context.ActionArguments.Values));
        }
        public override void OnResultExecuted(ResultExecutedContext context)
        {
            base.OnResultExecuted(context);
            Console.WriteLine("请求后" + context);
        }
    }
}